import { z } from "zod";
import { deleteTransaction } from '../../../service/fund.js';


export default {
    api: "deleteFunds",
    name: "删除账务记录",
    description: "根据客户提供的信息修改🔝账务明细，比如：删除账务明细1。",
    requestSchema: z.union([
        z.number().describe("账务明细ID"),
        z.object({
            id: z.number().describe("账务明细ID"),
        }),
        z.array(z.number().describe("账务明细ID"))
    ]),
    func: async (params, context) => {
        const deleteIdList = [];
        if (Array.isArray(params)) {
            for (const id of params) {
                deleteIdList.push(id);
                await deleteTransaction(id, context.book.id, context.user.id);
            }
        } else if (typeof params === 'object') {
            deleteIdList.push(params.id);
        } else {
            deleteIdList.push(params);
        }

        for (const id of deleteIdList) {
            await deleteTransaction(id, context.book.id, context.user.id);
        }
        return `账务明细ID ${deleteIdList.join(',')} 已成功删除。`;
    }
}